<?php
	include '../init.php';
	//最终的图片集合
	$photo=array();
	//文章封面图
	$sql="SELECT img FROM article ";
	$result=$mysql->getAll($sql);
	//网站轮播图
	$jbanner = get_config('banner');
	$banner = json_decode($jbanner,true);
	$ban=array();
	foreach ($banner as $key => $value) {
		$ban[]=$value['banner'];
	}
	// 网站图片
	$sql="SELECT settingvalue FROM setting WHERE settingkey='sitelogo' ";
	$logo=$mysql->getOne($sql);
	if (!empty($logo)) {
		$photo[]=$logo;
	}
	//文章封面
	foreach ($result as $key => $value) {
		foreach ($value as $key => $v) {
			$photo[]=$v;
		}
	}
	//图片轮播
	foreach ($ban as $key => $value) {
			$photo[]=$value;
	}
	// print_r($photo);

	$handler = opendir('../public/upload');//打开文件路径
	while( ($filename = readdir($handler)) !== false ) {
	      //3、目录下都会有两个文件，名字为’.'和‘..’，不要对他们进行操作
	      if($filename != "." && $filename != ".."){
	          	// echo $filename;
		      	if (!in_array($filename,$photo)) {
		      		unlink('../public/upload/'.$filename);//文件不在我们需要的数据库中，就删除文件
		      	}
	      }
	}
	closedir($handler);
	header("location:index.php");